<%-- 
  - Author: Neha Chauhan
  - Date: 08-May-2011
  - Copyright Notice: TRAKHEES
  - Description: list.jsp
 --%>

<%@ include file="/WEB-INF/view/include.jsp"%>
<%@ page import="ae.pcfc.etks.online.web.*"%>


<c:choose>
	<c:when
		test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
		<script language="Javascript" type="text/javascript"
			src='<c:url value="/resources/js/jqgrid/grid.locale-ar.js"/>'></script>
	</c:when>
	<c:otherwise>
		<script language="Javascript" type="text/javascript"
			src='<c:url value="/resources/js/jqgrid/grid.locale-en.js"/>'></script>
	</c:otherwise>
</c:choose>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.base.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.common.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.formedit.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.inlinedit.js"/>'></script>

<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.custom.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/jquery.fmatter.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.filter.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.jqueryui.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.import.js"/>'></script>
	
<script type="text/javascript">
    $.jgrid.no_legacy_api = true;
    $.jgrid.useJSON = true;
</script>
	
<script type="text/javascript">
	$()
			.ready(
					function() {

						$('#grid')
						.jqGrid(
								{
									datatype :'json',
									url		 :'${pageContext.request.contextPath}/admin/general/service/register/displayServicesTable.json',
									height: 'auto', 
									colNames : [ '<spring:message code="label.id" />',
													'<spring:message code="label.servicename.eng" />','<spring:message code="label.servicename.arb" />','<spring:message code="label.service.type" />' ],
									
									colModel : [ {
										name:'serviceId',
										index : 'serviceId',
										width : 60,
										align : 'center'
									}, {
										name:'serviceNameEng',
										index : 'serviceNameEng',
										width : 400,
										align : 'center',
										sortable : true
									},{
										name:'serviceNameArb',
										index : 'serviceNameArb',
										width : 400,
										align : 'center',
										sortable : true
									},{
										name:'serviceType',
										index : 'serviceType',
										width : 400,
										align : 'center',
										sortable : true
									} ],
									rowNum:10, 
									autowidth: true, 
									viewrecords: true,
									rowList:[10,20,30], 
									pager: jQuery('#pager'), 
									sortname: 'serviceId', 
									viewrecords: true, 
									sortorder: "desc", 
									caption : '<spring:message code="label.user.services" />'
									<c:if test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
									, direction:'rtl'
									</c:if>									
								}).navGrid('#pager', {
							edit : false,
							add : false,
							del : false,
							search : true,
							searchtext:'<spring:message code="label.button.search" />'
						})
						$("#grid").navButtonAdd('#pager',
								   {  caption:'<spring:message code="label.button.delete" />',
								    buttonicon:"ui-icon-trash",
								    onClickButton: deleteRow,
								    position: "last",
								    title:"Delete",
								    cursor: "pointer"
								   }
								  );
						$("#grid").navButtonAdd('#pager',
								   {  caption:'<spring:message code="label.button.add" />',
								    buttonicon:"ui-icon-plus",
								    onClickButton: addRow,
								    position: "last",
								    title:"Add",
								    cursor: "pointer"
								   }
								  );
						$("#grid").navButtonAdd('#pager',
								   {  caption:'<spring:message code="label.edit" />',
								    buttonicon:"ui-icon ui-icon-pencil",
								    onClickButton: edit,
								    position: "last",
								    title:"",
								    cursor: "pointer"
								   }
								  );						  
						$("#grid").navButtonAdd('#pager',
								   {  caption:'<spring:message code="label.view" />',
								    buttonicon:"ui-icon-note",
								    onClickButton: viewRecord,
								    position: "last",
								    title:'<spring:message code="label.view" />',
								    cursor: "pointer"
								   }
								  );
	
	
		function deleteRow() {
		 // Get the currently selected row
		    var row = $('#grid').jqGrid('getGridParam','selrow');
		    		 
		    // A pop-up dialog will appear to confirm the selected action
		 if( row != null )
			 $('#grid').jqGrid( 'delGridRow', row,
		           {
					  url: "admin/general/service/register/delete.json?row="+row,
				      recreateForm: true,
		               beforeShowForm: function(form) {
		                 //change title
		                 $(".delmsg").replaceWith('<span>' +
		                   '<spring:message code="label.service.del.confirm.message" />?' + '</span>');
		                  
		        		//hide arrows
		                 $('#pData').hide(); 
		                 $('#nData').hide(); 
		               },
		              reloadAfterSubmit:false,
		              closeAfterDelete: true,
		              afterComplete : function (response, postdata, formid) {
		                  var result = eval('(' + response.responseText + ')');
	  	       			  var errors = '<spring:message code="error.delete.service" />';
					      if(result == false){
					    	  jAlert('error',errors,
										'<spring:message code="label.error" />');
					    	  $("#grid").trigger("reloadGrid");
						  }
		     		 }
		           });
		  else{
			   //$( "#dialogSelectRow" ).dialog();
			  jAlert('error','<spring:message code="error.service.select" />', '<spring:message code="label.errormessage" />');
		  }
		
		}
		
		function addRow(){
			window.location = "${pageContext.request.contextPath}/admin/general/service/register/form.htm";
		}
		function edit(){
			var row = $('#grid').jqGrid('getGridParam','selrow');
			if(row == null)
			{
				jAlert('error','<spring:message code="error.service.select" />', '<spring:message code="label.errormessage" />');	
			}
			else{
				var serviceId = $('#grid').jqGrid('getCell',row,'serviceId');
				window.location = "${pageContext.request.contextPath}/admin/general/service/register/edit.htm?serviceId="+serviceId;
			}
		}
		
		});

	
	function viewRecord() {
		var row = $('#grid').jqGrid('getGridParam','selrow');
		if(row == null)
		{
			jAlert('error','<spring:message code="error.service.select" />', '<spring:message code="label.errormessage" />');	
		}
		else{
			var serviceId = $('#grid').jqGrid('getCell',row,'serviceId');
			if(serviceId != null && serviceId != ''){
				$.ajax({
					type : "POST",
					url : "admin/general/service/register/view/show.htm?serviceId=" + serviceId,
					cache : false,
					contentType : "application/html",
					dataType : "html",
					success : function(result) {
						$("#serviceInfo").html(result);
						$("#popupDialog").dialog(
								{
									autoOpen : true,
									width : 800,
									height : 400,
									maxHeight : 800,
									buttons : {
										'<spring:message code="label.button.close" />' : {
											'text': '<spring:message code="label.button.close" />',
											'class': 'close',																		
											'click' : function() {
											$(this)
													.dialog(
															"close");
											}
										}
									},
									modal : true,
									title : '<spring:message code="label.service" />'
						});					
					}
				});
			}
		}
	}
</script>

<div id="container" dir='<spring:message code="page.dir"/>'
	align='<spring:message code="page.align"/>'>
		<%
					if(session.getAttribute(ConstantsAdmin.SUCCESS_PARAM) != null) {
				%>
		<script type="text/javascript">
				$(document)
						.ready(
								function() {
									jAlert(
											'success','<%=session.getAttribute(ConstantsAdmin.SUCCESS_PARAM)%>',
											'<spring:message code="msg.success" />');
								});
			</script>			

		<%
			session.removeAttribute(ConstantsAdmin.SUCCESS_PARAM);
		}  %>




	<div id="search"></div>
	<table id="grid">
			</table>
			<span id="pager"></span>
			
	
	<div id="popupDialog" style="display: none;" dir='<spring:message code="page.dir"/>'  align='<spring:message code="page.align"/>' class="t_form-left t_fin-black">
		<div id="serviceInfo" ></div>	
	</div>

</div>